package com.example.daytest.manyThread;

import java.util.concurrent.locks.ReentrantLock;

public class ManyThread implements Runnable{

    private static int ticket = 100;
    ReentrantLock lock=new ReentrantLock();
    @Override
    public void run() {
        while (true){
            lock.lock();
            try {

                if(ticket>0){
                    System.out.println(Thread.currentThread().getName()+"-------"+ticket);
                    ticket--;
                }else{
                    break;
                }
            } finally {
                lock.unlock();

            }
        }
    }
}
class Test {
    private static int num=0;
    public static void main(String[] args) {
//        ManyThread myThread = new ManyThread();
//        new Thread(myThread).start();
//        new Thread(myThread).start();
//        new Thread(myThread).start();


//        long start = System.currentTimeMillis();
//        for (int i = 0; i <100 ; i++) {
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    num++;
//                }
//            }).start();
//
//        }

//        System.out.println(num);
//        long end = System.currentTimeMillis();
//        System.out.println(end-start);
    }
}
